<template>
    <div class="app-container">
      <el-row :gutter="10">
        <el-col :span="24" :xs="24">
          <!-- 数据筛选表单 -->
          <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="60px">
            <!-- 数据筛选表单组件 -->
            <el-form-item label="标题" prop="title">
              <el-input
                v-model="queryParams.title"
                placeholder="请输入模块标题"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
           
            <el-form-item label="类型" prop="businessType">
              <el-input
                v-model="queryParams.businessType"
                placeholder="请输入业务类型"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="方式" prop="requestMethod">
              <el-input
                v-model="queryParams.requestMethod"
                placeholder="请输入请求方式"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            
            <el-form-item label="结果" prop="resultCode">
              <el-input
                v-model="queryParams.resultCode"
                placeholder="请输入请求结果编码"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            
            <!-- 数据筛选操作按钮 -->
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
              >搜索
              </el-button>
              <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetQuery"
              >重置
              </el-button>
            </el-form-item>
          </el-form>
          <el-row :gutter="10" class="mb8">
            <el-col :span="3">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="small"
                :disabled="multiple"
                @click="handleDelete"
              >批量删除
              </el-button>
            </el-col>
          </el-row>
          
          <!-- 数据表格 -->
          <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
            <!-- 数据表格列 -->
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column label="ID" align="center" prop="logId" width="60px" />
            <el-table-column label="标题" align="center" prop="title" width="200px" />
            <!-- <el-table-column label="目标对象" align="center" prop="target" width="350px" /> -->
            <el-table-column label="方法名称" align="center" prop="method" width="100px" />
            <el-table-column label="业务类型" align="center" prop="businessType" width="100px" />
            <el-table-column label="请求方式" align="center" prop="requestMethod" width="100px" />
            <el-table-column label="请求url" align="center" prop="requestUrl" />
            <el-table-column label="请求结果" align="center" prop="resultCode" width="80px" />
            <el-table-column label="请求者" align="center" prop="requestBy" width="80px" />
            <el-table-column label="请求时间" align="center" prop="requestTime" width="250px" />
          </el-table>
          <!-- 数据分页加载 -->
          <el-pagination
            :current-page="pageNum"
            :page-sizes="[5, 10, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            @pagination="getList"
          />
        </el-col>
      </el-row>
    </div>
  </template>
  
  <script>
  /** 导入axios Api */
  import { listLogByPage, deleteLogByIds } from '@/api/log'
  export default {
    name: 'Log',
    data() {
      return {
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非选择禁用
        multiple: true,
        // 当前页
        pageNum: 0,
        // 每页数据量
        pageSize: 0,
        // Log表格数据
        logList: [],
        // 数据查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 5,
          title: undefined,
          businessType: undefined,
          requestMethod: undefined,
          resultCode: undefined
        },
        // 数据编辑表单
        form: {},
        // 表单数据校验规则
        rules: {
          logId: [
            { required: true, message: '日志主键不能为空', trigger: 'blur' }
          ],
          title: [
            { required: true, message: '模块标题不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询Log数据列表 */
      getList() {
        this.loading = true
        listLogByPage(this.queryParams).then((response) => {
          this.logList = response.data.list
          this.total = response.data.total
          this.loading = false
        })
      },
      /** 处理分页 */
      handleSizeChange(val) {
        this.queryParams.pageSize = val
        this.getList()
      },
      handleCurrentChange(val) {
        this.queryParams.pageNum = val
        this.getList()
      },
  
      /** 数据编辑对话框取消按钮 */
      cancel() {
        this.open = false
        this.resetForm()
      },
  
      /** 数据编辑表单清空 */
      resetForm() {
        this.form = {
          logId: undefined,
          title: undefined,
          target: undefined,
          method: undefined,
          businessType: undefined,
          requestMethod: undefined,
          requestUrl: undefined,
          resultCode: undefined,
          requestBy: undefined,
          requestTime: undefined
        }
      },
      
      /** 重置分页 */
      resetQueryParams() {
        this.queryParams.pageNum = 1
        this.queryParams.pageSize = 5
      },
  
      /** 数据筛选搜索按钮 */
      handleQuery() {
        this.resetQueryParams()
        this.getList()
        this.$message.success('查询成功')
      },
  
      /** 数据筛选重置按钮 */
      resetQuery() {
        this.$refs.queryForm.resetFields()
        this.getList()
      },
  
       // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.logId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      
      /** 删除按钮操作 */
      handleDelete() {
        deleteLogByIds(this.ids).then(response => {
          this.$message.success(response.msg)
          this.getList()
        })
      }
    }
  }
  </script>